package com.example.springboot.mapper;


import com.example.springboot.entity.ExportProduct;
import com.example.springboot.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {

    //查询所有产品
    @Select("select * from `proinfo`")
    List<Product> selectAll();


    //插入单个产品
    @Insert("insert into `proinfo` (proName, authName, proStatus, startDate, deadline, charger, notes) " +
            "values (#{proName}, #{authName}, #{proStatus}, #{startDate}, #{deadline}, #{charger}, #{notes} )")
    void insertPro(Product product);

    //根据负责人和产品名称筛选
    @Select("select * from `proinfo` where charger=#{charger}  and proName=#{proName} ")
    List<Product> selectByChargerProName(String charger, String proName);

    //根据产品名称筛选
    @Select("select * from `proinfo` where proName=#{proName}")
    List<Product> selectByProName(String proName);

    //根据负责人筛选
    @Select("select * from `proinfo` where charger=#{charger}")
    List<Product> selectByCharger(String charger);

    //首页功能——通过负责人和产品名称锁定需要编辑的产品认证任务,进行编辑
    @Update("update `proinfo` set  authName = #{ authName }, startDate = #{startDate}," +
            " deadline = #{deadline}, proStatus = #{proStatus}, charger = #{charger}, notes = #{notes} " +
            "where id=#{id} and charger = #{charger} and  proName = #{proName}")
    void updateByChargerProName(Product newProduct);

    //删除——根据id单个进行删除
    @Delete("delete from `proinfo` where id=#{id}")
    void deleteById(Integer id);

    //第三方认证界面——获取需要第三方认证的数据—ID值为偶数
    @Select("SELECT * FROM `proinfo` WHERE ID % 2 = 0;")
    List<Product> selectEvenID();

    //第三方认证界面——获取需要第三方认证的数据—ID值为偶数
    @Select("SELECT * FROM `proinfo` WHERE ID % 2 = 0;")
    List<ExportProduct> selectEvenIDThird();
}
